<!DOCTYPE html>
<meta charset="UTF-8">
<form id="myselectaudit" style="margin-top: 20px">
	<div class="layui-form-item">
		<div class="layui-inline">
			<label class="layui-form-label">编号：</label>
			<div class="layui-input-inline">
				<input type="text" name="username" id="username" class="layui-input"  placeholder="请输入用户名"/>
			</div>
		</div>
	

		<div class="layui-inline">
			<div class="layui-btn-group ">
				<button type="button" class="layui-btn layui-icon layui-icon-search"onclick="searchaudit()">查询</button>
				<button type="button" class="layui-btn layui-icon layui-icon-circle"onclick="emptyaudit()">清空</button>
			</div>
		</div>
	</div>
</form>
<table id="audit_table" lay-filter="audit_table"></table>

<script type="text/html" id="barDemo">
	<button class="layui-btn layui-btn-sm " lay-event="pass">同意</button>
	<button class="layui-btn layui-btn-sm layui-btn-danger" lay-event="refuse">拒绝</button>
</script>
<script>
	layui.use('table', function(){
	  var table = layui.table;
	  table.render({
		  	title:'学生列表',
		  	color:'#666',
			height: 'auto',
		    elem: '#audit_table',
		    url:'audit/page',
		    toolbar: '#toolbar',
		    page: true,
		    cols: [
		    	[
		      {type:'checkbox'},
		      {field:'username', width:'12%', title: '用户名'},
		      {field:'name', width:'12%', title: '姓名'},
		      {field:'phone', width:'12%', title: '联系电话'},
		      {field:'title', width:'12%', title: '书名'},
		      {field:'borrowData', width:'12%', title: '借书时间'},
		      {field:'returnData', width:'12%', title: '还书时间'},
		      {field:'state', width:'12%', title: '状态'},
		      {field:'right', title: '操作', width:'12%',toolbar:"#barDemo"}
		   	 ]
		    ]
	  		
	  		});
	  table.on('tool(audit_table)', function(obj) {
			var data = obj.data;
			var id = data.id;
			if (obj.event === "pass") {
				$.post('audit/pass',{id:id,p:1},function(result){
					red();
					layer.alert("已同意");
				})
			}else if(obj.event==="refuse"){
				$.post('audit/pass',{id:id,p:2},function(result){
	   		 		red();
					layer.alert("已拒绝");
				})
			}
		});
	  });
	//清空
	function red(){
		var table = layui.table;
	  	table.reload('audit_table', {
		  url: 'audit/page'
		});
	}
	//查询
	function searchaudit(){
		var username = $('#username').val();
		layui.use('table', function(){
			var table = layui.table;
			table.reload('audit_table', {
				  url: 'audit/page',
				where: {
					username:username
				}
			});
		});
	}
	//清空表格
	function emptyaudit(){
		$("#myselectaudit")[0].reset();
		var username = $('#username').val();
		layui.use('table', function(){
			var table = layui.table;
		  	table.reload('audit_table', {
			  url: 'audit/page',
			  where: {
				  username:username
				}
			});
		});
	}
  </script>